package com.nobt.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.nobt.websocket.MyWebSocket;

@Controller  //注意这里必须为Controller，如果是reseController将不会被视图解析器解析
public class IndexController {
	
	@Autowired
	private MyWebSocket myWebSocket;

    @RequestMapping("/socket")
    public String socket() {
        return "/socket";
    }
    
	@SuppressWarnings("static-access")
	@RequestMapping("/topic/{message}")
    public String topic(@PathVariable String message) throws IOException {
		Map<String,String> returnMap = new HashMap<String,String>();
		returnMap.put("message", message);
		myWebSocket.sendInfo(message);
    	return "/success";
    }
}
